home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / a_predict.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-20  |  26.1 KB  |  1,622 lines

  1. ;    VirtualDub - Video processing and capture application
  2. ;    Copyright (C) 1998-2001 Avery Lee
  3. ;
  4. ;    This program is free software; you can redistribute it and/or modify
  5. ;    it under the terms of the GNU General Public License as published by
  6. ;    the Free Software Foundation; either version 2 of the License, or
  7. ;    (at your option) any later version.
  8. ;
  9. ;    This program is distributed in the hope that it will be useful,
  10. ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;    GNU General Public License for more details.
  13. ;
  14. ;    You should have received a copy of the GNU General Public License
  15. ;    along with this program; if not, write to the Free Software
  16. ;    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. ;****************************************************
  19. ;
  20. ;    There is an algorithm used here for MPEG motion prediction which is
  21. ;    hard to understand from the source code alone.  It is:
  22. ;
  23. ;        mov    edi,[ecx]
  24. ;        mov    ebx,[edx]
  25. ;        mov    eax,edi
  26. ;        xor    edi,ebx
  27. ;        shr    edi,1
  28. ;        adc    eax,ebx
  29. ;        rcr    eax,1
  30. ;        and    edi,00808080h
  31. ;        add    eax,edi
  32. ;        mov    [edx],eax
  33. ;
  34. ;    EDI holds a correction factor which compensates for odd LSB sum bits
  35. ;    that got added onto the MSB of the lower byte sum.  The ADD/RCR
  36. ;    does the addition; EDI is then added on to correct for 0/1 or 1/0
  37. ;    LSB sum bits.  The lowest bit is handled through the ADC:
  38. ;
  39. ;    A-LSB    B-LSB    XOR    Sum
  40. ;      0      0     0    00
  41. ;      0      1     1    10
  42. ;      1      0     1    10
  43. ;      1      1     0    10
  44. ;
  45. ;    This produces a fully correct MPEG-1 average of four pairs of samples
  46. ;    in only 5 clocks.  It is difficult to use, however, because the
  47. ;    SHR/ADC/RCR instructions all must issue in the U-pipe (port 0 on
  48. ;    the PII), and the carry must be undisturbed between the SHR and the
  49. ;    ADC
  50. ;
  51. ;****************************************************
  52.  
  53.     .586
  54.     .model    flat
  55.  
  56.  
  57.     .const
  58.  
  59.     align 16
  60.  
  61. predictors_Y        dd    predict_Y_normal
  62.             dd    predict_Y_halfpelX
  63.             dd    predict_Y_halfpelY
  64.             dd    predict_Y_quadpel
  65. adders_Y        dd    predict_add_Y_normal
  66.             dd    predict_add_Y_halfpelX
  67.             dd    predict_add_Y_halfpelY
  68.             dd    predict_add_Y_quadpel
  69.  
  70. predictors_C        dd    predict_C_normal
  71.             dd    predict_C_halfpelX
  72.             dd    predict_C_halfpelY
  73.             dd    predict_C_quadpel
  74. adders_C        dd    predict_add_C_normal
  75.             dd    predict_add_C_halfpelX
  76.             dd    predict_add_C_halfpelY
  77.             dd    predict_add_C_quadpel
  78.  
  79.  
  80.     .code
  81.  
  82. ;    video_copy_prediction(
  83. ;        YUVPixel *dst,
  84. ;        YUVPixel *src,
  85. ;        long vector_x,
  86. ;        long vector_y,
  87. ;        long plane_pitch);
  88.  
  89. src    equ    [esp+4+16]
  90. dst    equ    [esp+8+16]
  91. vx    equ    [esp+12+16]
  92. vy    equ    [esp+16+16]
  93. pitch    equ    [esp+20+16]
  94.  
  95.     public    _video_copy_prediction_Y_scalar
  96.  
  97.     align    16
  98. _video_copy_prediction_Y_scalar:
  99.     push    ebp
  100.     push    edi
  101.     push    esi
  102.     push    ebx
  103.  
  104.     mov    esi,pitch
  105.     mov    ecx,src
  106.     mov    eax,vx
  107.     mov    ebx,vy
  108.  
  109.     mov    edi,eax            ;edi = vx
  110.     mov    ebp,ebx            ;ebp = vy
  111.     sar    edi,1            ;edi = x
  112.     and    eax,1            ;eax = x half-pel
  113.     sar    ebp,1            ;ebp = y
  114.     add    ecx,edi            ;ecx = src + x
  115.     imul    ebp,esi            ;ebp = y*pitch
  116.     add    ecx,ebp            ;ecx = src + x + y*pitch
  117.     and    ebx,1            ;ebx = y half-pel
  118.     shl    eax,2
  119.     mov    edx,dst
  120.     call    dword ptr [predictors_Y+eax+ebx*8]
  121.  
  122.     pop    ebx
  123.     pop    esi
  124.     pop    edi
  125.     pop    ebp
  126.     ret
  127.  
  128. ;*********************************************************
  129. ;*
  130. ;*    Luminance - quadpel
  131. ;*
  132. ;*********************************************************
  133.  
  134.     align    16
  135. predict_Y_quadpel:
  136.     push    16
  137. loop_Y1_quadpel:
  138.  
  139. ;    [A][B][C][D][E][F][G][H]
  140. ;    [I][J][K][L][M][N][O][P]
  141.  
  142. quadpel_move    macro    off
  143.     mov    edi,[ecx+off]
  144.     mov    ebp,0fcfcfcfch
  145.  
  146.     and    ebp,edi
  147.     and    edi,03030303h
  148.  
  149.     shr    ebp,2
  150.     mov    eax,[ecx+esi+off]
  151.  
  152.     mov    ebx,0fcfcfcfch
  153.     and    ebx,eax
  154.  
  155.     and    eax,03030303h
  156.     add    edi,eax
  157.  
  158.     shr    ebx,2
  159.     mov    eax,[ecx+1+off]
  160.  
  161.     add    ebp,ebx
  162.     mov    ebx,0fcfcfcfch
  163.  
  164.     and    ebx,eax
  165.     and    eax,03030303h
  166.  
  167.     shr    ebx,2
  168.     add    edi,eax
  169.  
  170.     add    ebp,ebx
  171.     mov    eax,[ecx+esi+1+off]
  172.  
  173.     add    edi,02020202h
  174.     mov    ebx,0fcfcfcfch
  175.  
  176.     and    ebx,eax
  177.     and    eax,03030303h
  178.  
  179.     shr    ebx,2
  180.     add    edi,eax
  181.  
  182.     shr    edi,2
  183.     add    ebp,ebx
  184.  
  185.     and    edi,03030303h
  186.     add    ebp,edi
  187.  
  188.     mov    [edx+off],ebp
  189.     endm
  190.  
  191.     quadpel_move    0
  192.     quadpel_move    4
  193.     quadpel_move    8
  194.     quadpel_move    12
  195.  
  196.     mov    eax,[esp]
  197.     lea    ecx,[ecx+esi]
  198.     dec    eax
  199.     lea    edx,[edx+esi]
  200.     mov    [esp],eax
  201.     jne    loop_Y1_quadpel
  202.     pop    eax
  203.     ret
  204.  
  205.  
  206. ;*********************************************************
  207. ;*
  208. ;*    Luminance - half-pel Y
  209. ;*
  210. ;*********************************************************
  211.  
  212.     align    16
  213. predict_Y_halfpelY:
  214.     push    16
  215. loop_Y1_halfpelV:
  216.     mov    edi,[ecx+0]
  217.     mov    ebx,[ecx+esi+0]
  218.     mov    eax,edi
  219.     xor    edi,ebx
  220.     shr    edi,1            ;u
  221.     mov    ebp,[ecx+4]
  222.     adc    eax,ebx            ;u
  223.     mov    ebx,[ecx+esi+4]
  224.     rcr    eax,1            ;u
  225.     and    edi,00808080h        ;v
  226.     add    eax,edi            ;u
  227.     xor    ebp,ebx
  228.     shr    ebp,1            ;u
  229.     mov    edi,[ecx+4]
  230.     adc    edi,ebx            ;u
  231.     mov    [edx+0],eax
  232.     rcr    edi,1            ;u
  233.     and    ebp,00808080h
  234.     add    edi,ebp
  235.     mov    ebx,[ecx+esi+8]
  236.     mov    [edx+4],edi
  237.     mov    edi,[ecx+8]
  238.     mov    eax,edi
  239.     xor    edi,ebx
  240.     shr    edi,1            ;u
  241.     mov    ebp,[ecx+12]
  242.     adc    eax,ebx            ;u
  243.     mov    ebx,[ecx+esi+12]
  244.     rcr    eax,1            ;u
  245.     and    edi,00808080h        ;v
  246.     add    eax,edi            ;u
  247.     xor    ebp,ebx
  248.     shr    ebp,1            ;u
  249.     mov    edi,[ecx+12]
  250.     adc    edi,ebx            ;u
  251.     mov    [edx+8],eax
  252.     rcr    edi,1            ;u
  253.     and    ebp,00808080h
  254.     add    edi,ebp
  255.     mov    eax,[esp]
  256.     add    ecx,esi
  257.     mov    [edx+12],edi
  258.     add    edx,esi
  259.     dec    eax
  260.     mov    [esp],eax
  261.     jne    loop_Y1_halfpelV
  262.  
  263.     pop    eax
  264.     ret
  265.  
  266. ;*********************************************************
  267. ;*
  268. ;*    Luminance - half-pel X
  269. ;*
  270. ;*********************************************************
  271.  
  272.     align    16
  273. predict_Y_halfpelX:
  274.     mov    edi,16
  275.     sub    edx,esi
  276. loop_Y1_halfpelX:
  277.  
  278.         mov    eax,[ecx]
  279.         mov    ebx,[ecx+4]
  280.  
  281.         shl    ebx,24
  282.         mov    ebp,eax
  283.  
  284.         shr    ebp,8
  285.         ;<-->
  286.  
  287.         or    ebx,ebp
  288.         mov    ebp,eax
  289.  
  290.         or    ebp,ebx
  291.         and    eax,0fefefefeh
  292.  
  293.         shr    eax,1
  294.         and    ebp,01010101h
  295.  
  296.         shr    ebx,1
  297.         add    eax,ebp
  298.  
  299.         and    ebx,07f7f7f7fh
  300.         add    eax,ebx
  301.  
  302.         mov    [edx+esi],eax
  303.  
  304.         ;<---------------------->
  305.  
  306.         mov    eax,[ecx+4]
  307.         mov    ebx,[ecx+8]
  308.  
  309.         shl    ebx,24
  310.         mov    ebp,eax
  311.  
  312.         shr    ebp,8
  313.  
  314.         or    ebx,ebp
  315.         mov    ebp,eax
  316.  
  317.         and    eax,0fefefefeh
  318.         or    ebp,ebx
  319.  
  320.         shr    eax,1
  321.         and    ebp,01010101h
  322.  
  323.         shr    ebx,1
  324.         add    eax,ebp
  325.  
  326.         and    ebx,07f7f7f7fh
  327.         add    eax,ebx
  328.  
  329.         mov    [edx+esi+4],eax
  330.  
  331.  
  332.  
  333.  
  334.  
  335.         mov    eax,[ecx+8]
  336.         mov    ebx,[ecx+12]
  337.  
  338.         shl    ebx,24
  339.         mov    ebp,eax
  340.  
  341.         shr    ebp,8
  342.         ;<-->
  343.  
  344.         or    ebx,ebp
  345.         mov    ebp,eax
  346.  
  347.         and    eax,0fefefefeh
  348.         or    ebp,ebx
  349.  
  350.         shr    eax,1
  351.         and    ebp,01010101h
  352.  
  353.         shr    ebx,1
  354.         add    eax,ebp
  355.  
  356.         and    ebx,07f7f7f7fh
  357.         add    eax,ebx
  358.  
  359.         mov    [edx+esi+8],eax
  360.  
  361.         ;<---------------------->
  362.  
  363.         mov    eax,[ecx+12]
  364.         mov    ebx,[ecx+16]
  365.  
  366.         shl    ebx,24
  367.         mov    ebp,eax
  368.  
  369.         shr    ebp,8
  370.         add    edx,esi
  371.  
  372.         or    ebx,ebp
  373.         mov    ebp,eax
  374.  
  375.         and    eax,0fefefefeh
  376.         or    ebp,ebx
  377.  
  378.         shr    eax,1
  379.         and    ebp,01010101h
  380.  
  381.         shr    ebx,1
  382.         add    eax,ebp
  383.  
  384.         and    ebx,07f7f7f7fh
  385.         add    eax,ebx
  386.  
  387.         mov    [edx+12],eax
  388.         add    ecx,esi
  389.  
  390.         dec    edi
  391.         jne    loop_Y1_halfpelX
  392.  
  393.  
  394.     ret
  395.  
  396.  
  397. ;*********************************************************
  398. ;*
  399. ;*    Luminance - normal
  400. ;*
  401. ;*********************************************************
  402.  
  403.     align    16
  404. predict_Y_normal:
  405.     mov    edi,8
  406. loop_Y:
  407.     mov    eax,[ecx]
  408.     mov    ebx,[ecx+4]
  409.     mov    [edx],eax
  410.     mov    [edx+4],ebx
  411.     mov    eax,[ecx+8]
  412.     mov    ebx,[ecx+12]
  413.     mov    [edx+8],eax
  414.     mov    [edx+12],ebx
  415.     mov    eax,[ecx+esi]
  416.     mov    ebx,[ecx+esi+4]
  417.     mov    [edx+esi],eax
  418.     mov    [edx+esi+4],ebx
  419.     mov    eax,[ecx+esi+8]
  420.     mov    ebx,[ecx+esi+12]
  421.     mov    [edx+esi+8],eax
  422.     mov    [edx+esi+12],ebx
  423.     lea    ecx,[ecx+esi*2]
  424.     lea    edx,[edx+esi*2]
  425.     dec    edi
  426.     jne    loop_Y
  427.     ret
  428.  
  429.  
  430.  
  431.  
  432. ;**************************************************************************
  433. ;*
  434. ;*
  435. ;*
  436. ;*  Addition predictors
  437. ;*
  438. ;*
  439. ;*
  440. ;**************************************************************************
  441.  
  442.     public    _video_add_prediction_Y_scalar
  443.     align    16
  444. _video_add_prediction_Y_scalar:
  445.     push    ebp
  446.     push    edi
  447.     push    esi
  448.     push    ebx
  449.  
  450.     mov    esi,pitch
  451.     mov    ecx,src
  452.     mov    eax,vx
  453.     mov    ebx,vy
  454.  
  455.     mov    edi,eax            ;edi = vx
  456.     mov    ebp,ebx            ;ebp = vy
  457.     sar    edi,1            ;edi = x
  458.     and    eax,1            ;eax = x half-pel
  459.     sar    ebp,1            ;ebp = y
  460.     add    ecx,edi            ;ecx = src + x
  461.     imul    ebp,esi            ;ebp = y*pitch
  462.     add    ecx,ebp            ;ecx = src + x + y*pitch
  463.     and    ebx,1            ;ebx = y half-pel
  464.     shl    eax,2
  465.     mov    edx,dst
  466.  
  467.     call    dword ptr [adders_Y+eax+ebx*8]
  468.  
  469.     pop    ebx
  470.     pop    esi
  471.     pop    edi
  472.     pop    ebp
  473.     ret
  474.  
  475. ;*********************************************************
  476. ;*
  477. ;*    Luminance - quadpel
  478. ;*
  479. ;*********************************************************
  480.  
  481.     align    16
  482. predict_add_Y_quadpel:
  483.     push    16
  484. add_loop_Y1_quadpel:
  485.  
  486. ;    [A][B][C][D][E][F][G][H]
  487. ;    [I][J][K][L][M][N][O][P]
  488.  
  489. quadpel_add    macro    off
  490. IF 0
  491.     mov    eax,[ecx+off]        ;EAX = [D][C][B][A] (#1)
  492.     mov    ebx,[ecx+1+off]        ;EBX = [E][D][C][B] (#2)
  493.     mov    edi,eax            ;EDI = [D][C][B][A] (#1)
  494.     mov    ebp,ebx            ;EBP = [E][D][C][B] (#2)
  495.     shr    edi,8            ;EDI = [0][D][C][B] (#1>>8)
  496.     and    eax,00ff00ffh        ;EAX = [ C ][ A ] (#1 even)
  497.     shr    ebp,8            ;EBP = [0][E][D][C] (#2>>8)
  498.     and    ebx,00ff00ffh        ;EBX = [ D ][ B ] (#2 even)
  499.     and    edi,00ff00ffh        ;EDI = [ D ][ B ] (#1 odd)
  500.     and    ebp,00ff00ffh        ;EBP = [ E ][ C ] (#2 odd)
  501.     add    eax,ebx            ;EAX = [C+D][A+B]
  502.     add    edi,ebp            ;EDI = [D+E][B+C]
  503.  
  504.     mov    ebx,[ecx+esi+off]    ;EBX = [L][K][J][I]
  505.     add    eax,00040004h        ;EAX = [C+D+4][A+B+4]
  506.  
  507.     mov    ebp,ebx            ;EBP = [L][K][J][I]
  508.     and    ebx,00ff00ffh        ;EBX = [ K ][ I ]
  509.     shr    ebp,8            ;EBP = [0][L][K][J]
  510.     add    eax,ebx            ;EAX = [C+D+K+4][A+B+I+4]
  511.     and    ebp,00ff00ffh        ;EBP = [ L ][ J ]
  512.     mov    ebx,[ecx+esi+1+off]    ;EBX = [M][L][K][J]
  513.     add    edi,ebp            ;EDI = [D+E+L][B+C+J]
  514.     mov    ebp,ebx            ;EBP = [M][L][K][J]
  515.     
  516.     shr    ebp,8            ;EBP = [0][M][L][K]
  517.     and    ebx,00ff00ffh        ;EBX = [ L ][ J ]
  518.  
  519.     add    eax,ebx            ;EAX = [C+D+K+L+4][A+B+I+J+4]
  520.     and    ebp,00ff00ffh        ;EBP = [ M ][ K ]
  521.  
  522.     mov    ebx,[edx+off]
  523.     add    edi,ebp            ;EDI = [D+E+L+M][B+C+J+K]
  524.  
  525.     mov    ebp,ebx
  526.     and    ebp,0ff00ff00h
  527.  
  528.     shr    ebp,6
  529.     and    ebx,00ff00ffh
  530.  
  531.     shl    ebx,2
  532.     add    edi,ebp
  533.  
  534.     add    eax,ebx
  535.     add    edi,00040004h
  536.     
  537.     shl    edi,5
  538.     and    eax,07f807f8h
  539.  
  540.     shr    eax,3
  541.     and    edi,0ff00ff00h
  542.  
  543.     or    eax,edi
  544.     mov    [edx+off],eax
  545. ELSE
  546.     mov    edi,[ecx+off]
  547.     mov    ebp,0f8f8f8f8h
  548.  
  549.     and    ebp,edi
  550.     and    edi,07070707h
  551.  
  552.     shr    ebp,3
  553.     mov    eax,[ecx+esi+off]
  554.  
  555.     mov    ebx,0f8f8f8f8h
  556.     and    ebx,eax
  557.  
  558.     and    eax,07070707h
  559.     add    edi,eax
  560.  
  561.     shr    ebx,3
  562.     mov    eax,[ecx+1+off]
  563.  
  564.     add    ebp,ebx
  565.     mov    ebx,0f8f8f8f8h
  566.  
  567.     and    ebx,eax
  568.     and    eax,07070707h
  569.  
  570.     shr    ebx,3
  571.     add    edi,eax
  572.  
  573.     add    ebp,ebx
  574.     mov    eax,[ecx+esi+1+off]
  575.  
  576.     add    edi,04040404h
  577.     mov    ebx,0f8f8f8f8h
  578.  
  579.     and    ebx,eax
  580.     and    eax,07070707h
  581.  
  582.     shr    ebx,3
  583.     add    edi,eax
  584.  
  585.     mov    eax,[edx+off]
  586.     add    ebp,ebx
  587.  
  588.     mov    ebx,eax
  589.     and    eax,0fefefefeh
  590.  
  591.     shr    eax,1
  592.     and    ebx,01010101h
  593.  
  594.     shl    ebx,2
  595.     add    ebp,eax
  596.  
  597.     add    edi,ebx
  598.     shr    edi,3
  599.     and    edi,07070707h
  600.     add    ebp,edi
  601.  
  602.     mov    [edx+off],ebp
  603. ENDIF
  604.     endm
  605.  
  606.     quadpel_add    0
  607.     quadpel_add    4
  608.     quadpel_add    8
  609.     quadpel_add    12
  610.  
  611.     mov    eax,[esp]
  612.     lea    ecx,[ecx+esi]
  613.     dec    eax
  614.     lea    edx,[edx+esi]
  615.     mov    [esp],eax
  616.     jne    add_loop_Y1_quadpel
  617.     pop    eax
  618.     ret
  619.  
  620. ;*********************************************************
  621. ;*
  622. ;*    Luminance - half-pel Y
  623. ;*
  624. ;*********************************************************
  625.  
  626.     align    16
  627. predict_add_Y_halfpelY:
  628.     push    16
  629. add_loop_Y1_halfpelV:
  630.     mov    eax,[ecx]
  631.     mov    ebx,[edx]
  632.     mov    edi,eax
  633.     mov    ebp,ebx
  634.     and    eax,00ff00ffh
  635.     and    ebx,00ff00ffh
  636.     and    edi,0ff00ff00h
  637.     and    ebp,0ff00ff00h
  638.     shr    edi,8
  639.     shr    ebp,8
  640.     add    ebx,ebx
  641.     add    ebp,ebp
  642.     add    eax,ebx
  643.     add    edi,ebp
  644.  
  645.     mov    ebx,[ecx+esi]
  646.     mov    ebp,ebx
  647.     and    ebx,00ff00ffh
  648.     and    ebp,0ff00ff00h
  649.     shr    ebp,8
  650.     add    eax,ebx
  651.     add    edi,ebp
  652.  
  653.     add    eax,00020002h
  654.     add    edi,00020002h
  655.     shl    edi,6
  656.     shr    eax,2
  657.     and    eax,00ff00ffh
  658.     and    edi,0ff00ff00h
  659.     or    eax,edi
  660.     mov    [edx],eax
  661.  
  662.     mov    eax,[ecx+4]
  663.     mov    ebx,[edx+4]
  664.     mov    edi,eax
  665.     mov    ebp,ebx
  666.     and    eax,00ff00ffh
  667.     and    ebx,00ff00ffh
  668.     and    edi,0ff00ff00h
  669.     and    ebp,0ff00ff00h
  670.     shr    edi,8
  671.     shr    ebp,8
  672.     add    ebx,ebx
  673.     add    ebp,ebp
  674.     add    eax,ebx
  675.     add    edi,ebp
  676.  
  677.     mov    ebx,[ecx+esi+4]
  678.     mov    ebp,ebx
  679.     and    ebx,00ff00ffh
  680.     and    ebp,0ff00ff00h
  681.     shr    ebp,8
  682.     add    eax,ebx
  683.     add    edi,ebp
  684.  
  685.     add    eax,00020002h
  686.     add    edi,00020002h
  687.     shl    edi,6
  688.     shr    eax,2
  689.     and    eax,00ff00ffh
  690.     and    edi,0ff00ff00h
  691.     or    eax,edi
  692.     mov    [edx+4],eax
  693.  
  694.     mov    eax,[ecx+8]
  695.     mov    ebx,[edx+8]
  696.     mov    edi,eax
  697.     mov    ebp,ebx
  698.     and    eax,00ff00ffh
  699.     and    ebx,00ff00ffh
  700.     and    edi,0ff00ff00h
  701.     and    ebp,0ff00ff00h
  702.     shr    edi,8
  703.     shr    ebp,8
  704.     add    ebx,ebx
  705.     add    ebp,ebp
  706.     add    eax,ebx
  707.     add    edi,ebp
  708.  
  709.     mov    ebx,[ecx+esi+8]
  710.     mov    ebp,ebx
  711.     and    ebx,00ff00ffh
  712.     and    ebp,0ff00ff00h
  713.     shr    ebp,8
  714.     add    eax,ebx
  715.     add    edi,ebp
  716.  
  717.     add    eax,00020002h
  718.     add    edi,00020002h
  719.     shl    edi,6
  720.     shr    eax,2
  721.     and    eax,00ff00ffh
  722.     and    edi,0ff00ff00h
  723.     or    eax,edi
  724.     mov    [edx+8],eax
  725.  
  726.     mov    eax,[ecx+12]
  727.     mov    ebx,[edx+12]
  728.     mov    edi,eax
  729.     mov    ebp,ebx
  730.     and    eax,00ff00ffh
  731.     and    ebx,00ff00ffh
  732.     and    edi,0ff00ff00h
  733.     and    ebp,0ff00ff00h
  734.     shr    edi,8
  735.     shr    ebp,8
  736.     add    ebx,ebx
  737.     add    ebp,ebp
  738.     add    eax,ebx
  739.     add    edi,ebp
  740.  
  741.     mov    ebx,[ecx+esi+12]
  742.     mov    ebp,ebx
  743.     and    ebx,00ff00ffh
  744.     and    ebp,0ff00ff00h
  745.     shr    ebp,8
  746.     add    eax,ebx
  747.     add    edi,ebp
  748.  
  749.     add    eax,00020002h
  750.     add    edi,00020002h
  751.     shl    edi,6
  752.     shr    eax,2
  753.     and    eax,00ff00ffh
  754.     and    edi,0ff00ff00h
  755.     or    eax,edi
  756.     mov    [edx+12],eax
  757.  
  758.     add    ecx,esi
  759.     add    edx,esi
  760.  
  761.     dec    dword ptr [esp]
  762.     jne    add_loop_Y1_halfpelV
  763.     pop    eax
  764.     ret
  765.  
  766.  
  767. ;*********************************************************
  768. ;*
  769. ;*    Luminance - half-pel X
  770. ;*
  771. ;*********************************************************
  772.  
  773.     align    16
  774. predict_add_Y_halfpelX:
  775.     mov    edi,16
  776.     sub    edx,esi
  777. add_loop_Y1_halfpelX:
  778.     mov    eax,[ecx]
  779.     mov    ebx,[ecx+1]
  780.     mov    ebp,ebx
  781.     add    edx,esi
  782.  
  783.     shr    ebx,2
  784.     or    ebp,eax
  785.     shr    eax,2
  786.     and    ebx,03f3f3f3fh
  787.     and    eax,03f3f3f3fh
  788.     shr    ebp,1
  789.     add    eax,ebx
  790.  
  791.     mov    ebx,[edx]
  792.  
  793.     or    ebp,ebx
  794.     and    ebx,0fefefefeh
  795.     shr    ebx,1
  796.     and    ebp,01010101h
  797.     add    eax,ebx
  798.  
  799.     add    eax,ebp
  800.     mov    [edx],eax
  801.  
  802.  
  803.     mov    eax,[ecx+4]
  804.     mov    ebx,[ecx+5]
  805.     mov    ebp,ebx
  806.  
  807.     shr    ebx,2
  808.     or    ebp,eax
  809.     shr    eax,2
  810.     and    ebx,03f3f3f3fh
  811.     and    eax,03f3f3f3fh
  812.     shr    ebp,1
  813.     add    eax,ebx
  814.  
  815.     mov    ebx,[edx+4]
  816.     or    ebp,ebx
  817.     and    ebx,0fefefefeh
  818.     shr    ebx,1
  819.     and    ebp,01010101h
  820.     add    eax,ebx
  821.  
  822.     add    eax,ebp
  823.     mov    [edx+4],eax
  824.  
  825.  
  826.  
  827.  
  828.  
  829.     mov    eax,[ecx+8]
  830.     mov    ebx,[ecx+9]
  831.     mov    ebp,ebx
  832.  
  833.     shr    ebx,2
  834.     or    ebp,eax
  835.     shr    eax,2
  836.     and    ebx,03f3f3f3fh
  837.     and    eax,03f3f3f3fh
  838.     shr    ebp,1
  839.     add    eax,ebx
  840.  
  841.     mov    ebx,[edx+8]
  842.  
  843.     or    ebp,ebx
  844.     and    ebx,0fefefefeh
  845.     shr    ebx,1
  846.     and    ebp,01010101h
  847.     add    eax,ebx
  848.  
  849.     add    eax,ebp
  850.     mov    [edx+8],eax
  851.  
  852.  
  853.     mov    eax,[ecx+12]
  854.     mov    ebx,[ecx+13]
  855.     mov    ebp,ebx
  856.     add    ecx,esi
  857.  
  858.     shr    ebx,2
  859.     or    ebp,eax
  860.     shr    eax,2
  861.     and    ebx,03f3f3f3fh
  862.     and    eax,03f3f3f3fh
  863.     shr    ebp,1
  864.     add    eax,ebx
  865.  
  866.     mov    ebx,[edx+12]
  867.     or    ebp,ebx
  868.     and    ebx,0fefefefeh
  869.     shr    ebx,1
  870.     and    ebp,01010101h
  871.     add    eax,ebx
  872.  
  873.     add    eax,ebp
  874.     mov    [edx+12],eax
  875.  
  876.  
  877.     
  878.  
  879.     dec    edi
  880.     jne    add_loop_Y1_halfpelX
  881.     ret
  882.  
  883.  
  884.  
  885.  
  886.  
  887. ;*********************************************************
  888. ;*
  889. ;*    Luminance - normal
  890. ;*
  891. ;*    See note at top, or this will be unreadable.
  892. ;*
  893. ;*********************************************************
  894.  
  895.     align    16
  896. predict_add_Y_normal:
  897.     push    16
  898. add_loop_Y1_addX:
  899.     mov    edi,[ecx+0]        ;u
  900.     mov    ebx,[edx+0]        ;v
  901.     mov    eax,edi            ;u
  902.     xor    edi,ebx            ;v
  903.     shr    edi,1            ;u
  904.     mov    ebp,[ecx+4]        ;v
  905.     adc    eax,ebx            ;u
  906.     mov    ebx,[edx+4]        ;v
  907.     rcr    eax,1            ;u
  908.     and    edi,00808080h        ;v
  909.     add    eax,edi            ;u
  910.     xor    ebp,ebx            ;v
  911.     shr    ebp,1            ;u
  912.     mov    edi,[ecx+4]        ;v
  913.     adc    edi,ebx            ;u
  914.     mov    [edx+0],eax        ;v
  915.     rcr    edi,1            ;u
  916.     and    ebp,00808080h        ;v
  917.     add    edi,ebp            ;u
  918.     mov    ebx,[edx+8]        ;v
  919.     mov    [edx+4],edi        ;u
  920.     mov    edi,[ecx+8]        ;v
  921.     mov    eax,edi            ;u
  922.     xor    edi,ebx            ;v
  923.     shr    edi,1            ;u
  924.     mov    ebp,[ecx+12]        ;v
  925.     adc    eax,ebx            ;u
  926.     mov    ebx,[edx+12]        ;v
  927.     rcr    eax,1            ;u
  928.     and    edi,00808080h        ;v
  929.     add    eax,edi            ;u
  930.     xor    ebp,ebx            ;v
  931.     shr    ebp,1            ;u
  932.     mov    edi,[ecx+12]        ;v
  933.     adc    edi,ebx            ;u
  934.     mov    [edx+8],eax        ;v
  935.     rcr    edi,1            ;u
  936.     and    ebp,00808080h        ;v
  937.     add    edi,ebp            ;u
  938.     mov    eax,[esp+0]        ;v
  939.     add    ecx,esi            ;u
  940.     mov    [edx+12],edi        ;v
  941.     add    edx,esi            ;u
  942.     dec    eax            ;v
  943.     mov    [esp+0],eax        ;u
  944.     jne    add_loop_Y1_addX    ;v
  945.  
  946.     pop    eax
  947.  
  948.     ret
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958. ;**************************************************************************
  959.  
  960. ;    video_copy_prediction_C(
  961. ;        YUVPixel *dst,
  962. ;        YUVPixel *src,
  963. ;        long vector_x,
  964. ;        long vector_y,
  965. ;        long plane_pitch);
  966.  
  967. src    equ    [esp+4+16]
  968. dst    equ    [esp+8+16]
  969. vx    equ    [esp+12+16]
  970. vy    equ    [esp+16+16]
  971. pitch    equ    [esp+20+16]
  972.  
  973.     public    _video_copy_prediction_C_scalar
  974.  
  975.     align    16
  976. _video_copy_prediction_C_scalar:
  977.     push    ebp
  978.     push    edi
  979.     push    esi
  980.     push    ebx
  981.  
  982.     mov    esi,pitch
  983.     mov    ecx,src
  984.     mov    eax,vx
  985.     mov    ebx,vy
  986.  
  987.     mov    edi,eax            ;edi = vx
  988.     mov    ebp,ebx            ;ebp = vy
  989.     sar    edi,1            ;edi = x
  990.     and    eax,1            ;eax = x half-pel
  991.     sar    ebp,1            ;ebp = y
  992.     add    ecx,edi            ;ecx = src + x
  993.     imul    ebp,esi            ;ebp = y*pitch
  994.     add    ecx,ebp            ;ecx = src + x + y*pitch
  995.     and    ebx,1            ;ebx = y half-pel
  996.     shl    eax,2
  997.     mov    edx,dst
  998.     call    dword ptr [predictors_C+eax+ebx*8]
  999.     pop    ebx
  1000.     pop    esi
  1001.     pop    edi
  1002.     pop    ebp
  1003.     ret
  1004.  
  1005. ;*********************************************************
  1006. ;*
  1007. ;*    Luminance - quadpel
  1008. ;*
  1009. ;*********************************************************
  1010.  
  1011.     align    16
  1012. predict_C_quadpel:
  1013.     push    8
  1014. loop_C1_quadpel:
  1015.  
  1016. ;    [A][B][C][D][E][F][G][H]
  1017. ;    [I][J][K][L][M][N][O][P]
  1018.  
  1019. quadpel_move    macro    off
  1020.     mov    eax,[ecx+off]        ;EAX = [D][C][B][A] (#1)
  1021.     mov    ebx,[ecx+1+off]        ;EBX = [E][D][C][B] (#2)
  1022.     mov    edi,eax            ;EDI = [D][C][B][A] (#1)
  1023.     mov    ebp,ebx            ;EBP = [E][D][C][B] (#2)
  1024.     shr    edi,8            ;EDI = [0][D][C][B] (#1>>8)
  1025.     and    eax,00ff00ffh        ;EAX = [ C ][ A ] (#1 even)
  1026.     shr    ebp,8            ;EBP = [0][E][D][C] (#2>>8)
  1027.     and    ebx,00ff00ffh        ;EBX = [ D ][ B ] (#2 even)
  1028.     and    edi,00ff00ffh        ;EDI = [ D ][ B ] (#1 odd)
  1029.     and    ebp,00ff00ffh        ;EBP = [ E ][ C ] (#2 odd)
  1030.     add    eax,ebx            ;EAX = [C+D][A+B]
  1031.     add    edi,ebp            ;EDI = [D+E][B+C]
  1032.  
  1033.     mov    ebx,[ecx+esi+off]    ;EBX = [L][K][J][I]
  1034.     add    eax,00020002h        ;EAX = [C+D+4][A+B+4]
  1035.  
  1036.     mov    ebp,ebx            ;EBP = [L][K][J][I]
  1037.     and    ebx,00ff00ffh        ;EBX = [ K ][ I ]
  1038.     shr    ebp,8            ;EBP = [0][L][K][J]
  1039.     add    eax,ebx            ;EAX = [C+D+K+4][A+B+I+4]
  1040.     and    ebp,00ff00ffh        ;EBP = [ L ][ J ]
  1041.     mov    ebx,[ecx+esi+1+off]    ;EBX = [M][L][K][J]
  1042.     add    edi,ebp            ;EDI = [D+E+L][B+C+J]
  1043.     mov    ebp,ebx            ;EBP = [M][L][K][J]
  1044.     
  1045.     shr    ebp,8            ;EBP = [0][M][L][K]
  1046.     add    edi,00020002h
  1047.  
  1048.     and    ebx,00ff00ffh        ;EBX = [ L ][ J ]
  1049.     and    ebp,00ff00ffh        ;EBP = [ M ][ K ]
  1050.  
  1051.     add    edi,ebp            ;EDI = [D+E+L+M][B+C+J+K]
  1052.     add    eax,ebx            ;EAX = [C+D+K+L+4][A+B+I+J+4]
  1053.     
  1054.     shl    edi,6
  1055.     and    eax,03fc03fch
  1056.  
  1057.     shr    eax,2
  1058.     and    edi,0ff00ff00h
  1059.  
  1060.     or    eax,edi
  1061.     mov    [edx+off],eax
  1062.     endm
  1063.  
  1064.     quadpel_move    0
  1065.     quadpel_move    4
  1066.  
  1067.     mov    eax,[esp]
  1068.     lea    ecx,[ecx+esi]
  1069.     dec    eax
  1070.     lea    edx,[edx+esi]
  1071.     mov    [esp],eax
  1072.     jne    loop_C1_quadpel
  1073.     pop    eax
  1074.     ret
  1075.  
  1076.  
  1077.  
  1078.  
  1079. ;*********************************************************
  1080. ;*
  1081. ;*    Luminance - half-pel Y
  1082. ;*
  1083. ;*********************************************************
  1084.  
  1085.     align    16
  1086. predict_C_halfpelY:
  1087.     mov    edi,8
  1088. loop_C1_halfpelV:
  1089.  
  1090.     mov    eax,[ecx]
  1091.     mov    ebx,[ecx+esi]
  1092.     mov    ebp,eax
  1093.     and    eax,0fefefefeh
  1094.     or    ebp,ebx
  1095.     and    ebx,0fefefefeh
  1096.     shr    eax,1
  1097.     and    ebp,01010101h
  1098.     shr    ebx,1
  1099.     add    eax,ebp
  1100.     add    ebx,eax
  1101.  
  1102.     mov    eax,[ecx+4]
  1103.     mov    [edx],ebx
  1104.     
  1105.     mov    ebx,[ecx+esi+4]
  1106.     add    ecx,esi
  1107.  
  1108.     mov    ebp,eax
  1109.     and    eax,0fefefefeh
  1110.     or    ebp,ebx
  1111.     and    ebx,0fefefefeh
  1112.     shr    eax,1
  1113.     and    ebp,01010101h
  1114.     shr    ebx,1
  1115.     add    eax,ebp
  1116.  
  1117.     add    eax,ebx
  1118.     dec    edi
  1119.  
  1120.     mov    [edx+4],eax
  1121.     lea    edx,[edx+esi]
  1122.  
  1123.     jne    loop_C1_halfpelV
  1124.  
  1125.     ret
  1126.  
  1127.  
  1128. ;*********************************************************
  1129. ;*
  1130. ;*    Luminance - half-pel X
  1131. ;*
  1132. ;*********************************************************
  1133.  
  1134.     align    16
  1135. predict_C_halfpelX:
  1136.     mov    edi,8
  1137.     sub    edx,esi
  1138. loop_C1_halfpelX:
  1139.  
  1140.     mov    eax,[ecx]
  1141.     mov    ebx,[ecx+4]
  1142.  
  1143.     shl    ebx,24
  1144.     mov    ebp,eax
  1145.  
  1146.     shr    ebp,8
  1147.     ;<-->
  1148.  
  1149.     or    ebx,ebp
  1150.     mov    ebp,eax
  1151.  
  1152.     or    ebp,ebx
  1153.     and    eax,0fefefefeh
  1154.  
  1155.     shr    eax,1
  1156.     and    ebp,01010101h
  1157.  
  1158.     shr    ebx,1
  1159.     add    eax,ebp
  1160.  
  1161.     and    ebx,07f7f7f7fh
  1162.     add    eax,ebx
  1163.  
  1164.     mov    [edx+esi],eax
  1165.  
  1166.     ;<---------------------->
  1167.  
  1168.     mov    eax,[ecx+4]
  1169.     mov    ebx,[ecx+8]
  1170.  
  1171.     shl    ebx,24
  1172.     mov    ebp,eax
  1173.  
  1174.     shr    ebp,8
  1175.     add    edx,esi
  1176.  
  1177.     or    ebx,ebp
  1178.     mov    ebp,eax
  1179.  
  1180.     or    ebp,ebx
  1181.     and    eax,0fefefefeh
  1182.  
  1183.     shr    eax,1
  1184.     and    ebp,01010101h
  1185.  
  1186.     shr    ebx,1
  1187.     add    eax,ebp
  1188.  
  1189.     and    ebx,07f7f7f7fh
  1190.     add    eax,ebx
  1191.  
  1192.     mov    [edx+4],eax
  1193.     add    ecx,esi
  1194.  
  1195.     dec    edi
  1196.     jne    loop_C1_halfpelX
  1197.     ret
  1198.  
  1199.  
  1200. ;*********************************************************
  1201. ;*
  1202. ;*    Luminance - normal
  1203. ;*
  1204. ;*********************************************************
  1205.  
  1206.     align    16
  1207. predict_C_normal:
  1208.     mov    edi,4
  1209. loop_C:
  1210.     mov    eax,[ecx]
  1211.     mov    ebx,[ecx+4]
  1212.     mov    [edx],eax
  1213.     mov    [edx+4],ebx
  1214.     mov    eax,[ecx+esi]
  1215.     mov    ebx,[ecx+esi+4]
  1216.     mov    [edx+esi],eax
  1217.     mov    [edx+esi+4],ebx
  1218.     lea    ecx,[ecx+esi*2]
  1219.     lea    edx,[edx+esi*2]
  1220.     dec    edi
  1221.     jne    loop_C
  1222.     ret
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228. ;**************************************************************************
  1229. ;*
  1230. ;*
  1231. ;*
  1232. ;*  Addition predictors
  1233. ;*
  1234. ;*
  1235. ;*
  1236. ;**************************************************************************
  1237.  
  1238.     public    _video_add_prediction_C_scalar
  1239.  
  1240.     align    16
  1241. _video_add_prediction_C_scalar:
  1242.     push    ebp
  1243.     push    edi
  1244.     push    esi
  1245.     push    ebx
  1246.  
  1247.     mov    esi,pitch
  1248.     mov    ecx,src
  1249.     mov    eax,vx
  1250.     mov    ebx,vy
  1251.  
  1252.     mov    edi,eax            ;edi = vx
  1253.     mov    ebp,ebx            ;ebp = vy
  1254.     sar    edi,1            ;edi = x
  1255.     and    eax,1            ;eax = x half-pel
  1256.     sar    ebp,1            ;ebp = y
  1257.     add    ecx,edi            ;ecx = src + x
  1258.     imul    ebp,esi            ;ebp = y*pitch
  1259.     add    ecx,ebp            ;ecx = src + x + y*pitch
  1260.     and    ebx,1            ;ebx = y half-pel
  1261.     shl    eax,2
  1262.     mov    edx,dst
  1263.  
  1264.     call    dword ptr [adders_C+eax+ebx*8]
  1265.  
  1266.     pop    ebx
  1267.     pop    esi
  1268.     pop    edi
  1269.     pop    ebp
  1270.     ret
  1271.  
  1272. ;*********************************************************
  1273. ;*
  1274. ;*    Luminance - quadpel
  1275. ;*
  1276. ;*********************************************************
  1277.  
  1278.     align    16
  1279. predict_add_C_quadpel:
  1280.     push    8
  1281. add_loop_C1_quadpel:
  1282.  
  1283. ;    [A][B][C][D][E][F][G][H]
  1284. ;    [I][J][K][L][M][N][O][P]
  1285.  
  1286. quadpel_add    macro    off
  1287. IF 0
  1288.     mov    eax,[ecx+off]        ;EAX = [D][C][B][A] (#1)
  1289.     mov    ebx,[ecx+1+off]        ;EBX = [E][D][C][B] (#2)
  1290.  
  1291.     mov    edi,eax            ;EDI = [D][C][B][A] (#1)
  1292.     mov    ebp,ebx            ;EBP = [E][D][C][B] (#2)
  1293.  
  1294.     shr    edi,8            ;EDI = [0][D][C][B] (#1>>8)
  1295.     and    eax,00ff00ffh        ;EAX = [ C ][ A ] (#1 even)
  1296.  
  1297.     shr    ebp,8            ;EBP = [0][E][D][C] (#2>>8)
  1298.     and    ebx,00ff00ffh        ;EBX = [ D ][ B ] (#2 even)
  1299.  
  1300.     and    edi,00ff00ffh        ;EDI = [ D ][ B ] (#1 odd)
  1301.     and    ebp,00ff00ffh        ;EBP = [ E ][ C ] (#2 odd)
  1302.  
  1303.     add    eax,ebx            ;EAX = [C+D][A+B]
  1304.     add    edi,ebp            ;EDI = [D+E][B+C]
  1305.  
  1306.     mov    ebx,[ecx+esi+off]    ;EBX = [L][K][J][I]
  1307.     add    eax,00040004h        ;EAX = [C+D+4][A+B+4]
  1308.  
  1309.     mov    ebp,ebx            ;EBP = [L][K][J][I]
  1310.     and    ebx,00ff00ffh        ;EBX = [ K ][ I ]
  1311.  
  1312.     shr    ebp,8            ;EBP = [0][L][K][J]
  1313.     add    eax,ebx            ;EAX = [C+D+K+4][A+B+I+4]
  1314.  
  1315.     and    ebp,00ff00ffh        ;EBP = [ L ][ J ]
  1316.     mov    ebx,[ecx+esi+1+off]    ;EBX = [M][L][K][J]
  1317.  
  1318.     add    edi,ebp            ;EDI = [D+E+L][B+C+J]
  1319.     mov    ebp,ebx            ;EBP = [M][L][K][J]
  1320.     
  1321.     shr    ebp,8            ;EBP = [0][M][L][K]
  1322.     and    ebx,00ff00ffh        ;EBX = [ L ][ J ]
  1323.  
  1324.     add    eax,ebx            ;EAX = [C+D+K+L+4][A+B+I+J+4]
  1325.     and    ebp,00ff00ffh        ;EBP = [ M ][ K ]
  1326.  
  1327.     mov    ebx,[edx+off]
  1328.     add    edi,ebp            ;EDI = [D+E+L+M][B+C+J+K]
  1329.  
  1330.     mov    ebp,ebx
  1331.     and    ebp,0ff00ff00h
  1332.  
  1333.     shr    ebp,6
  1334.     and    ebx,00ff00ffh
  1335.  
  1336.     shl    ebx,2
  1337.     add    edi,ebp
  1338.  
  1339.     add    eax,ebx
  1340.     add    edi,00040004h
  1341.     
  1342.     shl    edi,5
  1343.     and    eax,07f807f8h
  1344.  
  1345.     shr    eax,3
  1346.     and    edi,0ff00ff00h
  1347.  
  1348.     or    eax,edi
  1349.     mov    [edx+off],eax
  1350. ELSE
  1351.     mov    edi,[ecx+off]
  1352.     mov    ebp,0f8f8f8f8h
  1353.  
  1354.     and    ebp,edi
  1355.     and    edi,07070707h
  1356.  
  1357.     shr    ebp,3
  1358.     mov    eax,[ecx+esi+off]
  1359.  
  1360.     mov    ebx,0f8f8f8f8h
  1361.     and    ebx,eax
  1362.  
  1363.     and    eax,07070707h
  1364.     add    edi,eax
  1365.  
  1366.     shr    ebx,3
  1367.     mov    eax,[ecx+1+off]
  1368.  
  1369.     add    ebp,ebx
  1370.     mov    ebx,0f8f8f8f8h
  1371.  
  1372.     and    ebx,eax
  1373.     and    eax,07070707h
  1374.  
  1375.     shr    ebx,3
  1376.     add    edi,eax
  1377.  
  1378.     add    ebp,ebx
  1379.     mov    eax,[ecx+esi+1+off]
  1380.  
  1381.     add    edi,04040404h
  1382.     mov    ebx,0f8f8f8f8h
  1383.  
  1384.     and    ebx,eax
  1385.     and    eax,07070707h
  1386.  
  1387.     shr    ebx,3
  1388.     add    edi,eax
  1389.  
  1390.     mov    eax,[edx+off]
  1391.     add    ebp,ebx
  1392.  
  1393.     mov    ebx,eax
  1394.     and    eax,0fefefefeh
  1395.  
  1396.     shr    eax,1
  1397.     and    ebx,01010101h
  1398.  
  1399.     shl    ebx,2
  1400.     add    ebp,eax
  1401.  
  1402.     add    edi,ebx
  1403.     shr    edi,3
  1404.     and    edi,07070707h
  1405.     add    ebp,edi
  1406.  
  1407.     mov    [edx+off],ebp
  1408. ENDIF
  1409.     endm
  1410.  
  1411.     quadpel_add    0
  1412.     quadpel_add    4
  1413.  
  1414.     mov    eax,[esp]
  1415.     lea    ecx,[ecx+esi]
  1416.     dec    eax
  1417.     lea    edx,[edx+esi]
  1418.     mov    [esp],eax
  1419.     jne    add_loop_C1_quadpel
  1420.     pop    eax
  1421.     ret
  1422.  
  1423.  
  1424. ;*********************************************************
  1425. ;*
  1426. ;*    Luminance - half-pel Y
  1427. ;*
  1428. ;*********************************************************
  1429.  
  1430.     align    16
  1431. predict_add_C_halfpelY:
  1432.     push    8
  1433. add_loop_C1_halfpelV:
  1434.     mov    eax,[ecx]
  1435.     mov    ebx,[edx]
  1436.     mov    edi,eax
  1437.     mov    ebp,ebx
  1438.     and    eax,00ff00ffh
  1439.     and    ebx,00ff00ffh
  1440.     and    edi,0ff00ff00h
  1441.     and    ebp,0ff00ff00h
  1442.     shr    edi,8
  1443.     shr    ebp,8
  1444.     add    ebx,ebx
  1445.     add    ebp,ebp
  1446.     add    eax,ebx
  1447.     add    edi,ebp
  1448.  
  1449.     mov    ebx,[ecx+esi]
  1450.     mov    ebp,ebx
  1451.     and    ebx,00ff00ffh
  1452.     and    ebp,0ff00ff00h
  1453.     shr    ebp,8
  1454.     add    eax,ebx
  1455.     add    edi,ebp
  1456.  
  1457.     add    eax,00020002h
  1458.     add    edi,00020002h
  1459.     shl    edi,6
  1460.     shr    eax,2
  1461.     and    eax,00ff00ffh
  1462.     and    edi,0ff00ff00h
  1463.     or    eax,edi
  1464.     mov    [edx],eax
  1465.  
  1466.     mov    eax,[ecx+4]
  1467.     mov    ebx,[edx+4]
  1468.     mov    edi,eax
  1469.     mov    ebp,ebx
  1470.     and    eax,00ff00ffh
  1471.     and    ebx,00ff00ffh
  1472.     and    edi,0ff00ff00h
  1473.     and    ebp,0ff00ff00h
  1474.     shr    edi,8
  1475.     shr    ebp,8
  1476.     add    ebx,ebx
  1477.     add    ebp,ebp
  1478.     add    eax,ebx
  1479.     add    edi,ebp
  1480.  
  1481.     mov    ebx,[ecx+esi+4]
  1482.     mov    ebp,ebx
  1483.     and    ebx,00ff00ffh
  1484.     and    ebp,0ff00ff00h
  1485.     shr    ebp,8
  1486.     add    eax,ebx
  1487.     add    edi,ebp
  1488.  
  1489.     add    eax,00020002h
  1490.     add    edi,00020002h
  1491.     shl    edi,6
  1492.     shr    eax,2
  1493.     and    eax,00ff00ffh
  1494.     and    edi,0ff00ff00h
  1495.     or    eax,edi
  1496.     mov    [edx+4],eax
  1497.  
  1498.  
  1499.     add    ecx,esi
  1500.     add    edx,esi
  1501.  
  1502.     dec    dword ptr [esp]
  1503.     jne    add_loop_C1_halfpelV
  1504.     pop    eax
  1505.     ret
  1506.  
  1507.  
  1508. ;*********************************************************
  1509. ;*
  1510. ;*    Luminance - half-pel X
  1511. ;*
  1512. ;*********************************************************
  1513.  
  1514.     align    16
  1515. predict_add_C_halfpelX:
  1516.     mov    edi,8
  1517.     sub    edx,esi
  1518. add_loop_C1_halfpelX:
  1519.     mov    eax,[ecx]
  1520.     mov    ebx,[ecx+1]
  1521.     mov    ebp,ebx
  1522.     add    edx,esi
  1523.  
  1524.     shr    ebx,2
  1525.     or    ebp,eax
  1526.     shr    eax,2
  1527.     and    ebx,03f3f3f3fh
  1528.     and    eax,03f3f3f3fh
  1529.     shr    ebp,1
  1530.     add    eax,ebx
  1531.  
  1532.     mov    ebx,[edx]
  1533.  
  1534.     or    ebp,ebx
  1535.     and    ebx,0fefefefeh
  1536.     shr    ebx,1
  1537.     and    ebp,01010101h
  1538.     add    eax,ebx
  1539.  
  1540.     add    eax,ebp
  1541.     mov    [edx],eax
  1542.  
  1543.  
  1544.     mov    eax,[ecx+4]
  1545.     mov    ebx,[ecx+5]
  1546.     mov    ebp,ebx
  1547.     add    ecx,esi
  1548.  
  1549.     shr    ebx,2
  1550.     or    ebp,eax
  1551.     shr    eax,2
  1552.     and    ebx,03f3f3f3fh
  1553.     and    eax,03f3f3f3fh
  1554.     shr    ebp,1
  1555.     add    eax,ebx
  1556.  
  1557.     mov    ebx,[edx+4]
  1558.     or    ebp,ebx
  1559.     and    ebx,0fefefefeh
  1560.     shr    ebx,1
  1561.     and    ebp,01010101h
  1562.     add    eax,ebx
  1563.  
  1564.     add    eax,ebp
  1565.     mov    [edx+4],eax
  1566.  
  1567.  
  1568.     
  1569.  
  1570.     dec    edi
  1571.     jne    add_loop_C1_halfpelX
  1572.     ret
  1573.  
  1574.  
  1575.  
  1576.  
  1577. ;*********************************************************
  1578. ;*
  1579. ;*    Luminance - normal
  1580. ;*
  1581. ;*********************************************************
  1582.  
  1583.     align    16
  1584. predict_add_C_normal:
  1585.     mov    edi,8
  1586. add_loop_C1_addX:
  1587.  
  1588.     mov    eax,[ecx]
  1589.     mov    ebx,[edx]
  1590.     mov    ebp,eax
  1591.     and    eax,0fefefefeh
  1592.     shr    eax,1
  1593.     or    ebp,ebx
  1594.     shr    ebx,1
  1595.     and    ebp,001010101h
  1596.     and    ebx,07f7f7f7fh
  1597.     add    ebp,eax
  1598.     add    ebx,ebp
  1599.     mov    eax,[ecx+4]
  1600.     mov    [edx],ebx
  1601.     mov    ebx,[edx+4]
  1602.     mov    ebp,eax
  1603.     and    eax,0fefefefeh
  1604.     shr    eax,1
  1605.     or    ebp,ebx
  1606.     shr    ebx,1
  1607.     and    ebp,001010101h
  1608.     and    ebx,07f7f7f7fh
  1609.     add    ebp,eax
  1610.     add    ebx,ebp
  1611.     add    ecx,esi
  1612.     mov    [edx+4],ebx
  1613.     add    edx,esi
  1614.  
  1615.     dec    edi
  1616.     jne    add_loop_C1_addX
  1617.     ret
  1618.  
  1619.  
  1620.     end
  1621.  
  1622.